package com.lmonkey.servlet.user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lmonkey.entity.LMONKEY_USER;
import com.lmonkey.service.LMONKEY_USERDao;

/**
 * Servlet implementation class ToUserUpdate
 */
@WebServlet("/userupdate")
public class UserUpdate extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		
		String userid = request.getParameter("userID");
		String username = request.getParameter("userName");
		String sex = request.getParameter("sex");
		String birthday = request.getParameter("birthDay");
		int status = 2;
		
		
		//创建用户实体
		LMONKEY_USER user = new LMONKEY_USER(userid, username, "", sex, birthday, null, "", "" ,"", status);
		
		//加入到数据库的用户表中
		int count = LMONKEY_USERDao.userupdate(user);
		

		//成功或失败重定向到哪里
		
		if(count >0 ) {
			
			response.sendRedirect("userselect?id="+userid);
		} else {
			PrintWriter out = response.getWriter();
			
			out.write("<script>");
			out.write("alert('信息修改失败')");
			out.write("location.href='manage/admin_touserupdate?id="+username+"'");
			out.write("</script>");
			
		}
	}


}
